/*
 * Pawn.cpp
 *
 *  Created on: Mar 6, 2011
 *      Author: Michael Ziminsky
 */

#include "Pawn.h"

namespace model
{
	namespace piece
	{
		Pawn::Pawn(bool light) : ChessPiece(light){};

		myTypes::moveSet Pawn::getPotentialMoves(const ChessBoard& b) const
		{
			myTypes::moveSet moves(new myTypes::moveSet::element_type);
			if (currLoc)
			{
				int dir = isLight ? 1 : -1;
				cellCheck(b, getOffsetLocation(UP, *currLoc, dir), moves);
				if (((isLight && currLoc->row == 2) || (!isLight && currLoc->row == 7)) && moves->size() == 1)
						cellCheck(b, getOffsetLocation(UP, *currLoc, 2 * dir), moves);
				cellCheck(b, getOffsetLocation(LEFTUP, *currLoc, dir), moves);
				cellCheck(b, getOffsetLocation(RIGHTUP, *currLoc, dir), moves);
			}
			return moves;
		}

		bool Pawn::cellCheck(const ChessBoard& b, const Location& l, myTypes::moveSet& moves) const
		{
			unsigned int initSize = moves->size();
			bool cont = ChessPiece::cellCheck(b, l, moves);
			if ((cont && l.col != currLoc->col) || (!cont && l.col == currLoc->col && initSize < moves->size())) moves->erase(l);
			return cont;
		}
	}
} // namespace model
